f = open('BMR.txt', 'a+')
while True:
    xh = input("是否退出程序(yes/no):")
    if xh == "yes":
        print("期待您的下一次测试！")
        break

    try:
        gender = input("请输入您的性别:")
        weight = float(input("请输入您的体重（kg）:"))
        height = int(input("请输入您的身高（cm）:"))
        age = int(input("请输入您的年龄:"))
    except ValueError:
        print("输入错误，请重新输入！")

    if gender == "男":
        bmr = 13.7 * weight + 5.0 * height - 6.8 * age + 66
    elif gender == "女":
        bmr = 9.6 * weight + 1.8 * height - 4.7 * age + 655
    else:
        print("性别输入错误，请重新输入！")
        continue
    print("基础代谢率为：{:.2f}大卡".format(bmr))

    info = '性别:{} 体重:{} 身高:{} 年龄:{} BMR={:.2f}\n'.format(gender, weight, height, age, bmr)
    print(info)
    f.write(info)
f.close()














